﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.EntityKeywords.Service
{
    public class EntityKeywordAppService : BaseAppService, IEntityKeywordAppService
    {
        private IEntityKeywordDomainService _domainService;

        public EntityKeywordAppService(IEntityKeywordDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ENTITYKEYWORD, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ENTITYKEYWORD, AuditAction.CREATE)]
        public EntityKeywordDto Add(Guid entityId, EntityKeywordCreateDto dto)
        {
            dto.EntityId = entityId;
            EntityKeyword entityKeyword = _domainService.Create(Mapper.Map<EntityKeyword>(dto));
            return Mapper.Map<EntityKeywordDto>(entityKeyword);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ENTITYKEYWORD, AuditAction.UPDATE)]
        public EntityKeywordDto Update(Guid id, EntityKeywordUpdateDto dto)
        {
            EntityKeyword entityKeyword = _domainService.Update(Mapper.Map<EntityKeywordUpdateBo>(dto));
            return Mapper.Map<EntityKeywordDto>(entityKeyword);
        }

        public EntityKeywordDto Get(Guid id)
        {
            EntityKeyword entityKeyword = _domainService.Get(id);
            return Mapper.Map<EntityKeywordDto>(entityKeyword);
        }

        public IEnumerable<EntityKeywordDto> GetList(Guid entityId)
        {
            IEnumerable<EntityKeyword> list = _domainService.GetByEntityId(entityId);
            return Mapper.Map<IEnumerable<EntityKeywordDto>>(list);
        }
    }
}
